// src/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import audio from './modules/audio'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    searchQuery: '',
    verificationCode: null, // 验证码
    codeTimer: null // 验证码清除定时器
  },
  modules: {
    audio: audio,
  },
  actions: {},
  mutations: {
    SET_SEARCH_QUERY(state, value) {
      state.searchQuery = value
    },
    SET_VERIFICATION_CODE(state, code) {
      state.verificationCode = code
      // 清除之前的定时器
      if (state.codeTimer) {
        clearTimeout(state.codeTimer)
      }
      // 2分钟后清空验证码
      state.codeTimer = setTimeout(() => {
        state.verificationCode = null
        state.codeTimer = null
      }, 120000) // 2分钟 = 120000毫秒
    },
    CLEAR_VERIFICATION_CODE(state) {
      state.verificationCode = null
      if (state.codeTimer) {
        clearTimeout(state.codeTimer)
        state.codeTimer = null
      }
    }
  }
})